package struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import personne.Personne;

import struts.actionForm.ActionFormPersonneCode;

import dao.DAOPersonneHBM;
import dao.DaoPersonne;

public class ActionAfficherPersonneCode extends Action {
	private DaoPersonne dao;

	public ActionAfficherPersonneCode()
	{
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception {
		// TODO Auto-generated method stub
		ActionFormPersonneCode bean = (ActionFormPersonneCode)form;
		Personne p = dao.get(bean.getCode());
		if(p==null)
		{
			ActionErrors errors = new ActionErrors();
			errors.add("Code inexistant" ,new ActionMessage("ActionAfficherPersonneCode.Erreur.Code.Inexistant"));
			saveErrors(request, errors);
			return mapping.findForward("erreurs");
		}
		//request.setAttribute("personne", p);
		HttpSession session = request.getSession();
		session.setAttribute("personne", p);
		return mapping.findForward("AfficherPersonneCode");

	}

	public DaoPersonne getDao() {
		return dao;
	}

	public void setDao(DaoPersonne dao) {
		this.dao = dao;
	}
	
	

}
